from pydantic import BaseModel
from typing import List, Optional
import datetime

# For parsing request from user
class ParseRequest(BaseModel):
    text: str

# For the response from the AI parser
class ParseResponse(BaseModel):
    dish_name: str
    ingredients: List[str]
    method: List[str]
    comment: Optional[str] = None
    self_critique: Optional[str] = None

# Base schema for a recipe
class RecipeBase(BaseModel):
    dish_name: str
    ingredients: List[str]
    method: List[str]
    comment: Optional[str] = None
    self_critique: Optional[str] = None
    image_urls: Optional[List[str]] = []

# Schema for creating a recipe (used in POST request)
class RecipeCreate(RecipeBase):
    pass

# Schema for reading a recipe (used in API response)
class Recipe(RecipeBase):
    id: int
    log_date: datetime.date
    created_at: datetime.datetime

    class Config:
        from_attributes = True

# For Qiniu upload token response
class TokenResponse(BaseModel):
    token: str
    domain: str

# Schema for updating a recipe
class RecipeUpdate(BaseModel):
    dish_name: Optional[str] = None
    ingredients: Optional[List[str]] = None
    method: Optional[List[str]] = None
    comment: Optional[str] = None
    self_critique: Optional[str] = None
    image_urls: Optional[List[str]] = None
